import { getStream } from '../Core/connect'
import * as MathUtils from '../Math/MathUtils'
/* 
    测量工具类，其中直接集成测距与测量面积，应注意是否有冲突，如测距结束之前不能测量面积
    测距方法：开始测距，结束测距，重开测距，
            开始测面积，结束侧面积，重开侧面积，
            清除测量对象
*/
export class MeasureTool {
    uuid: string
    isMeasureing:boolean
    name: string

    // listenmessagefun:Function
    constructor() {
        this.uuid = MathUtils.generateUUID()
        this.name = 'MeasureTool'
        this.isMeasureing = false
    }

    //开始距离测量
    startDistance(){
        if(this.isMeasureing ){
            alert('正在测量请先结束测量')
            return 0 
        }else{
            const stream = getStream()
            const str = {MeasureToolfunction: 'startDistance', ids: `${this.uuid}`}
            stream.emitUIInteraction(str)
            this.isMeasureing = true
        }
    }
    //停止距离测量
    stopDistance(){
        const stream = getStream()
        const str = {MeasureToolfunction: 'stopDistance', ids: `${this.uuid}`}
        stream.emitUIInteraction(str)
        this.isMeasureing = false
    }
    //开始面积测量
    startArea(){
        if(this.isMeasureing ){
            alert('正在测量请先结束测量')
            return 0
        }else{
            const stream = getStream()
            const str = {MeasureToolfunction: 'startArea', ids: `${this.uuid}`}
            stream.emitUIInteraction(str)
            this.isMeasureing = true
        }
    }
    //停止面积测量
    stopArea(){
        const stream = getStream()
        const str = {MeasureToolfunction: 'stopArea', ids: `${this.uuid}`}
        stream.emitUIInteraction(str)
        this.isMeasureing = false
    }
    //设置几何缩放尺寸
    setMeasureSize(size:number){
        const stream = getStream()
        const str = {MeasureToolfunction: 'setMeasureSize', ids: `${this.uuid}`,size:size}
        stream.emitUIInteraction(str)
    }
    //清除所有测量
    clearAll() {
        const stream = getStream()
        const str = {MeasureToolfunction: 'clearAll', ids: `${this.uuid}`}
        stream.emitUIInteraction(str)
	}
}